package tests;

import static org.junit.Assert.*;
import methods.DirectDepositMethod;
import methods.HoldMethod;
import methods.MailMethod;
import methods.PaymentMethod;

import org.junit.Assert;
import org.junit.Test;

import addEmployeeTransaction.AddHourlyEmployee;
import addEmployeeTransaction.AddSalariedEmployee;
import addEmployeeTransaction.Employee;
import affiliation.Affiliation;
import affiliation.UnionAffiliation;
import changeEmployeeTransaction.changeAffiliationTransaction.ChangeMemberTransaction;
import changeEmployeeTransaction.changeMethodTransaction.ChangeDirectTransaction;
import changeEmployeeTransaction.changeMethodTransaction.ChangeHoldTransaction;
import changeEmployeeTransaction.changeMethodTransaction.ChangeMailTransaction;
import database.InMemoryPayrollDatabase;
import database.PayrollDatabase;

public class TestMethods {

	PayrollDatabase database = InMemoryPayrollDatabase.getInstance();
	
	@Test
	public void ChangeDirectMethod() {
		int empId = 6;
		AddSalariedEmployee t =
			new AddSalariedEmployee(
				empId, "Mike", "Home", 3500.00, database);
		t.execute();
		ChangeDirectTransaction cddt =
			new ChangeDirectTransaction(empId, database);
		cddt.execute();
		Employee e = database.getEmployee(empId);
		assertNotNull(e);
		PaymentMethod method = e.getMethod();
		assertNotNull(method);
		assertTrue(method instanceof DirectDepositMethod);
	}
	
	@Test
	public void ChangeHoldMethod() {
		int empId = 7;
		AddSalariedEmployee t =
			new AddSalariedEmployee(
				empId, "Mike", "Home", 3500.00, database);
		t.execute();
		new ChangeDirectTransaction(empId, database).execute();
		ChangeHoldTransaction cht =
			new ChangeHoldTransaction(empId, database);
		cht.execute();
		Employee e = database.getEmployee(empId);
		assertNotNull(e);
		PaymentMethod method = e.getMethod();
		assertNotNull(method);
		assertTrue(method instanceof HoldMethod);
	}
	
	@Test
	public void ChangeMailMethod() {
		int empId = 8;
		AddSalariedEmployee t =
			new AddSalariedEmployee(
				empId, "Mike", "Home", 3500.00, database);
		t.execute();
		ChangeMailTransaction cmt =
			new ChangeMailTransaction(empId, database);
		cmt.execute();
		Employee e = database.getEmployee(empId);
		assertNotNull(e);
		PaymentMethod method = e.getMethod();
		assertNotNull(method);
		assertTrue(method instanceof MailMethod);
	}
	
	@Test
	public void ChangeUnionMember() {
		int empId = 9;
		AddHourlyEmployee t =
			new AddHourlyEmployee(empId, "Bill", "Home", 15.25, database);
		t.execute();
		int memberId = 7743;
		ChangeMemberTransaction cmt =
			new ChangeMemberTransaction(empId, memberId, 99.42, database);
		cmt.execute();
		Employee e = database.getEmployee(empId);
		assertNotNull(e);
		Affiliation affiliation = e.getAffiliation();
		assertNotNull(affiliation);
		assertTrue(affiliation instanceof UnionAffiliation);
		UnionAffiliation uf = (UnionAffiliation) affiliation;
		assertEquals(99.42, uf.getDues(), .001);
		Employee member = database.getUnionMember(memberId);
		assertNotNull(member);
		assertEquals(e, member);
	}
}
